
<template>
<div style="width: 430px;height: 932px;">
  <van-nav-bar
    title=""
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  />
    <van-list>
      <van-swipe-cell v-for="(item,index) in addmanagelist" :key="index" v-show="item.status==1">
        <p><van-button @click="tomoren(item.id)">设为默认</van-button>姓名：{{item.name}}|手机号：{{item.tel}}</p>
        <p>收货地址：{{item.address}} <van-button @click="todelete(item.id)">删除</van-button></p>
        <p>-----------------------------------------------------------------------</p>
      </van-swipe-cell>
      <van-button @click="onAdd()">新增地址</van-button>
    </van-list>
  <h1>我的默认地址</h1>
  <div class="info" @click="toOrderCon()">
    <div class="name-phone">
      <span>姓名：{{managelist.name}}</span>
      <span>手机号：{{managelist.tel}}</span>
    </div>
    <p><span>收货地址：{{managelist.address}}</span></p>
  </div>
  <van-popup v-model="show" style="width: 430px;height: 500px;">
    <el-form ref="form" :model="pojo">
      <el-form-item label="姓名">
        <el-input v-model="pojo.name"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="pojo.tel"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="pojo.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add()">添加</el-button>
      </el-form-item>
    </el-form>
  </van-popup>
</div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      form:{},
      pojo:{},
      show: false,
      addmanagelist:[],
      managelist:{},
      managelistId:0,
      detailsId:localStorage.getItem("detailsId"),
      addressId:localStorage.getItem("addressId"),
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    tomoren(id){
      axios.post("/addmanage/updatezt?id="+this.managelistId).then(res=>{
        this.findAddManage();
        this.findmanagelist();
      })
      axios.post("/addmanage/updatestatus?id="+id).then(res=>{
        this.$message(res.data.message);
        this.findAddManage();
        this.findmanagelist();
      })
    },
    findmanagelist(){
      axios.post('/addmanage/selectstatus').then(res=>{
        this.managelist = res.data.data.addManage;
        this.managelistId = res.data.data.addManage.id;
      })
    },
    toxuanze(id){
      axios.post("/addmanage/updatezt?id="+this.addressId).then(res=>{
        this.findAddManage();
      })
      axios.post("/addmanage/updatestatus?id="+id).then(res=>{
        this.$message(res.data.message);
        this.findAddManage();
      })
    },
    todelete(id){
      axios.post("/addmanage/deletemanage?id="+id).then(res=>{
        this.$message(res.data.message);
        this.findAddManage();
      })
    },
    add(){
      axios.post("/addmanage/add",this.pojo).then(res=>{
        this.$message(res.data.message);
        this.findAddManage();
        this.show = false;
      })
    },
    onAdd(){
      this.pojo = {};
      this.show = true;
    },
    findAddManage(){
      axios.post("/addmanage/findAddManage",this.form).then(res=>{
        this.addmanagelist = res.data.data.list;
      })
    }
  },
  created() {
    this.findAddManage();
    this.findmanagelist();
  }
}
</script>


<style scoped>

</style>
